package com.iplant.ams.controller.dms.scada;

import com.iplant.ams.service.DMSService;
import com.iplant.ams.service.po.dms.scada.status.DMSDeviceAreaStatus;
import com.iplant.ams.service.po.dms.scada.status.DMSDeviceStatistics;
import com.iplant.ams.service.po.dms.scada.status.DMSDeviceStatus;
import com.iplant.ams.service.po.dms.scada.status.DMSDeviceStatusStatistics;
import com.iplant.base.controller.BaseController;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.utils.RetCode;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.serializer.CloneTool;
import com.iplant.basic.service.po.bms.BMSEmployee;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/DMSDeviceStatus")
public class DMSDeviceStatusController extends BaseController {

    public DMSDeviceStatusController() {
        super();
    }

    @Autowired
    DMSService mDMSService;

    @GetMapping("/All")
    public Object All(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);

            String wName = StringUtils.parseString(request.getParameter("Name"));
            String wAssetNo = StringUtils.parseString(request.getParameter("AssetNo"));
            int wDeviceType = StringUtils.parseInt(request.getParameter("DeviceType"), -1);
            int wModelID = StringUtils.parseInt(request.getParameter("ModelID"), -1);
            int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"), -1);
            int wWorkShopID = StringUtils.parseInt(request.getParameter("WorkShopID"), -1);
            int wLineID = StringUtils.parseInt(request.getParameter("LineID"), -1);
            int wActive = StringUtils.parseInt(request.getParameter("Active"), -1);
            int wTeamID = StringUtils.parseInt(request.getParameter("TeamID"), -1);
            int wAreaID = StringUtils.parseInt(request.getParameter("AreaID"), -1);
            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));

            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceStatus>> wServiceResult = mDMSService.DMS_SelectDeviceStatusList(wBMSEmployee, wName,
                    wAssetNo, wDeviceType, wModelID, wFactoryID, wWorkShopID, wAreaID,
                    wActive, wStartTime, wEndTime, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.getResult(), wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("All", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }

    @GetMapping("/Current")

    public Object Current(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);

            int wDeviceID = StringUtils.parseInt(request.getParameter("DeviceID"));
            String wDeviceNo = StringUtils.parseString(request.getParameter("DeviceNo"));

            String wDeviceName = StringUtils.parseString(request.getParameter("DeviceName"));
            String wAssetNo = StringUtils.parseString(request.getParameter("AssetNo"));
            int wDeviceType = StringUtils.parseInt(request.getParameter("DeviceType"), -1);
            int wModelID = StringUtils.parseInt(request.getParameter("ModelID"), -1);
            int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"), -1);
            int wWorkShopID = StringUtils.parseInt(request.getParameter("WorkShopID"), -1);
            int wAreaID = StringUtils.parseInt(request.getParameter("AreaID"), -1);
            int wStatus = StringUtils.parseInt(request.getParameter("Status"), -1);
            Pagination wPagination = GetPagination(request, "DeviceIDL", "ASC");


            ServiceResult<List<DMSDeviceStatus>> wServiceResult = mDMSService.DMS_CurrentDeviceStatusList(wBMSEmployee,
                    wDeviceID, wDeviceNo, wDeviceName, wAssetNo, wDeviceType, wModelID, wFactoryID, wWorkShopID, wAreaID, wStatus, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.getResult(), wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("Current", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }


    @GetMapping("/CurrentArea")

    public Object CurrentArea(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {
            //统计 区域的不同状态数量

            BMSEmployee wBMSEmployee = GetSession(request);

            String wName = StringUtils.parseString(request.getParameter("Name"));
            String wAssetNo = StringUtils.parseString(request.getParameter("AssetNo"));
            int wDeviceType = StringUtils.parseInt(request.getParameter("DeviceType"), -1);
            int wModelID = StringUtils.parseInt(request.getParameter("ModelID"), -1);
            int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"), -1);
            int wWorkShopID = StringUtils.parseInt(request.getParameter("WorkShopID"), -1);
            int wAreaID = StringUtils.parseInt(request.getParameter("AreaID"), -1);
            int wStatus = StringUtils.parseInt(request.getParameter("Status"), -1);
            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceAreaStatus>> wServiceResult = mDMSService.DMS_CurrentDeviceStatusStatistics(wBMSEmployee, wName,
                    wAssetNo, wDeviceType, wModelID, wFactoryID, wWorkShopID, wAreaID, wStatus, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.getResult(), wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("CurrentArea", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }


    @GetMapping("/StatusTime")

    public Object StatusTime(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {
            //统计 区域的不同状态数量

            BMSEmployee wBMSEmployee = GetSession(request);
            List<Integer> wIDList = StringUtils.parseIntList(request.getParameter("DeviceIDList"), ",");
            String wDeviceNo = StringUtils.parseString(request.getParameter("DeviceNo"));
            List<String> wAssetNo = StringUtils.splitList(request.getParameter("AssetNo"),",");
            String wName = StringUtils.parseString(request.getParameter("Name"));
            int wDeviceType = StringUtils.parseInt(request.getParameter("DeviceType"), -1);
            int wModelID = StringUtils.parseInt(request.getParameter("ModelID"), -1);
            int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"), -1);
            int wWorkShopID = StringUtils.parseInt(request.getParameter("WorkShopID"), -1);
            int wAreaID = StringUtils.parseInt(request.getParameter("AreaID"), -1);

            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));
            ServiceResult<Map<Integer, Map<String, Integer>>> wServiceResult = mDMSService.DMS_SelectDeviceStatusTime(wBMSEmployee, wIDList, wDeviceNo, wName,
                    wAssetNo, wDeviceType, wModelID, wFactoryID, wWorkShopID,   wAreaID,   wStartTime, wEndTime);


            Map<String, Map<String, Integer>> wServiceRst = null;
            if (wServiceResult != null && wServiceResult.Result != null && wServiceResult.Result.size() > 0){
                for (Integer integer : wServiceResult.Result.keySet()) {
                    wServiceRst.put(integer+"",wServiceResult.Result.get(integer))   ;
                }
            }
            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {

                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", null, wServiceRst);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), null, wServiceRst);
            }
        } catch (Exception ex) {
            log.error("StatusTime", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }


    @GetMapping("/DeviceInfo")

    public Object DeviceInfo(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);

            int wID = StringUtils.parseInt(request.getParameter("DeviceID"), -1);
            String wDeviceNo = StringUtils.parseString(request.getParameter("DeviceNo"));
            String AssetNo = StringUtils.parseString(request.getParameter("AssetNo"));

            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime")) ;

            wEndTime.add(Calendar.DAY_OF_MONTH,1);

            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceStatus>> wServiceResult = mDMSService.DMS_SelectDeviceStatus(wBMSEmployee, wID,
                    wDeviceNo, AssetNo, wStartTime, wEndTime, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.Result, null);
            }
        } catch (Exception ex) {
            log.error("DeviceInfo", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }
    @GetMapping("/DeviceAll")

    public Object DeviceAll(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);

            List<Integer> wIDList = StringUtils.parseIntList(request.getParameter("DeviceIDList"), ",");

            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));

            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceStatus>> wServiceResult = mDMSService.DMS_SelectDeviceStatusList(wBMSEmployee,
                    wIDList, wStartTime, wEndTime, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.Result, null);
            }
        } catch (Exception ex) {
            log.error("DeviceAll", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }

    @GetMapping("/Statistics")

    public Object Statistics(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);


            int wDeviceID = StringUtils.parseInt(request.getParameter("DeviceID"), -1);
            String wDeviceNo = StringUtils.parseString(request.getParameter("DeviceNo"));
            String wDeviceName = StringUtils.parseString(request.getParameter("DeviceName"));
            String wAssetNo = StringUtils.parseString(request.getParameter("AssetNo"));
            int wDeviceType = StringUtils.parseInt(request.getParameter("DeviceType"), -1);
            int wModelID = StringUtils.parseInt(request.getParameter("ModelID"), -1);
            int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"), -1);
            int wWorkShopID = StringUtils.parseInt(request.getParameter("WorkShopID"), -1);
            int wAreaID = StringUtils.parseInt(request.getParameter("AreaID"), -1);
            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));
            wEndTime.add(Calendar.DAY_OF_MONTH,1);
            int wStatus = StringUtils.parseInt(request.getParameter("Status"), -1);

            int wHasAlarm = StringUtils.parseInt(request.getParameter("HasAlarm"));


            Boolean wIsCombine = StringUtils.parseBoolean(request.getParameter("IsCombine"));

            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceStatusStatistics>> wServiceResult = mDMSService.DMS_SelectDeviceStatusStatisticsList(wBMSEmployee, wDeviceID, wDeviceNo, wDeviceName,
                    wAssetNo, wDeviceType, wModelID, wFactoryID, wWorkShopID,  wAreaID,   wStatus, wIsCombine,  wStartTime, wEndTime, wPagination, wHasAlarm);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.getResult(), wPagination.getTotalPage());

                SetResult(wResult, "Alarm", wServiceResult.Get("Alarm",null));
                SetResult(wResult, "Frequency", wServiceResult.Get("Frequency",null));
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("Statistics", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }



    @GetMapping("/StatisticsTypeAll")

    public Object StatisticsTypeAll(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);


            List<Integer> wDeviceIDList = StringUtils.parseIntList(request.getParameter("DeviceID"), ",");

            int wLineID = StringUtils.parseInt(request.getParameter("LineID"), -1);
            String wAssetNo = StringUtils.parseString(request.getParameter("AssetNo"));
            int wStatType = StringUtils.parseInt(request.getParameter("StatType"));
            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));


            ServiceResult<List<DMSDeviceStatistics>> wServiceResult = mDMSService.DMS_SelectDeviceStatusDetailStatisticsTime(wBMSEmployee, wLineID, wDeviceIDList, wAssetNo, wStatType, wStartTime, wEndTime);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.getResult(), null);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("StatisticsTypeAll", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }


    @GetMapping("/DetailAll")

    public Object DetailAll(HttpServletRequest request) {

        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);

            String wName = StringUtils.parseString(request.getParameter("Name"));
            int wDeviceID = StringUtils.parseInt(request.getParameter("DeviceID"));
            String wAssetNo = StringUtils.parseString(request.getParameter("AssetNo"));
            int wDeviceType = StringUtils.parseInt(request.getParameter("DeviceType"), -1);
            int wModelID = StringUtils.parseInt(request.getParameter("ModelID"), -1);
            int wFactoryID = StringUtils.parseInt(request.getParameter("FactoryID"), -1);
            int wWorkShopID = StringUtils.parseInt(request.getParameter("WorkShopID"), -1);
            List<Integer> wStatus = StringUtils.parseIntList(request.getParameter("Status"), ",");
            int wAreaID = StringUtils.parseInt(request.getParameter("AreaID"), -1);
            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));
            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceStatus>> wServiceResult = mDMSService.DMS_SelectDeviceStatusDetailList(wBMSEmployee, wName, wDeviceID,
                    wAssetNo, wDeviceType, wModelID, wFactoryID, wWorkShopID,  wAreaID,
                    wStatus, wStartTime, wEndTime, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.getResult(), wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("DetailAll", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }

    @GetMapping("/DetailDeviceInfo")

    public Object DetailDeviceInfo(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);

            int wID = StringUtils.parseInt(request.getParameter("DeviceID"), -1);
            String wDeviceNo = StringUtils.parseString(request.getParameter("DeviceNo"));
            String AssetNo = StringUtils.parseString(request.getParameter("AssetNo"));

            List<Integer> wStatus = StringUtils.parseIntList(request.getParameter("Status"), ",");
            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));

            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceStatus>> wServiceResult = mDMSService.DMS_SelectDeviceStatusDetail(wBMSEmployee, wID,
                    wDeviceNo, AssetNo, wStatus, wStartTime, wEndTime, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.Result, null);
            }
        } catch (Exception ex) {
            log.error("DetailDeviceInfo", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }

    @GetMapping("/DetailDeviceAll")
    public Object DetailDeviceAll(HttpServletRequest request) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {

            BMSEmployee wBMSEmployee = GetSession(request);

            List<Integer> wIDList = StringUtils.parseIntList(request.getParameter("DeviceIDList"), ",");
            List<Integer> wStatus = StringUtils.parseIntList(request.getParameter("Status"), ",");
            Calendar wStartTime = StringUtils.parseCalendar(request.getParameter("StartTime"));
            Calendar wEndTime = StringUtils.parseCalendar(request.getParameter("EndTime"));

            Pagination wPagination = GetPagination(request);

            ServiceResult<List<DMSDeviceStatus>> wServiceResult = mDMSService.DMS_SelectDeviceStatusDetailList(wBMSEmployee,
                    wIDList, wStatus, wStartTime, wEndTime, wPagination);

            if (StringUtils.isEmpty(wServiceResult.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServiceResult.Result, wPagination.getTotalPage());
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServiceResult.getFaultCode(), wServiceResult.Result, null);
            }
        } catch (Exception ex) {
            log.error("DetailDeviceAll", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;
    }



    @PostMapping("/SyncStatusCurrent")

    public Object SyncStatusCurrent(HttpServletRequest request, @RequestBody Map<String, Object> wParam) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {


            BMSEmployee wBMSEmployee = GetSession(request);
            if (!wParam.containsKey("data")) {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, RetCode.SERVER_RST_ERROR_OUT);
                return wResult;
            }

            List<DMSDeviceStatus> wDMSDeviceStatusList = CloneTool.CloneArray(wParam.get("data"),DMSDeviceStatus.class);
            ServiceResult<List<String>> wServerRst = mDMSService.DMS_SyncDeviceStatusList(wBMSEmployee, wDMSDeviceStatusList);
            //数据库当前状态与数据当前状态对比 有变更则查询最后一条历史记录 与数据库当前状态对比 更新结束时间并添加变更历史记录
            //数据库当前状态变更为当前状态

            if (StringUtils.isEmpty(wServerRst.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServerRst.getResult(), null);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServerRst.getFaultCode(), wServerRst.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("SyncStatusCurrent", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;

    }

    @PostMapping("/SyncStatusHistory")

    public Object SyncStatusHistory(HttpServletRequest request, @RequestBody Map<String, Object> wParam) {
        Map<String, Object> wResult = new HashMap<String, Object>();
        try {


            BMSEmployee wBMSEmployee = GetSession(request);
            if (!wParam.containsKey("data")) {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, RetCode.SERVER_RST_ERROR_OUT);
                return wResult;
            }

            List<DMSDeviceStatus> wDMSDeviceStatusList =CloneTool.CloneArray(wParam.get("data"),DMSDeviceStatus.class);
            ServiceResult<List<String>> wServerRst = mDMSService.DMS_SyncDeviceStatusHistoryList(wBMSEmployee, wDMSDeviceStatusList);


            if (StringUtils.isEmpty(wServerRst.getFaultCode())) {
                wResult = GetResult(RetCode.SERVER_CODE_SUC, "", wServerRst.getResult(), null);
            } else {
                wResult = GetResult(RetCode.SERVER_CODE_ERR, wServerRst.getFaultCode(), wServerRst.getResult(), null);
            }
        } catch (Exception ex) {
            log.error("SyncStatusHistory", ex);
            wResult = GetResult(RetCode.SERVER_CODE_ERR, ex.getMessage());
        }
        return wResult;

    }


}
